var gulp = require('gulp');
var jade = require('gulp-jade');
var rename = require('gulp-rename')
var rev = require('gulp-rev')
var revCollector = require('gulp-rev-collector');
var browserify = require('browserify');
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');


var paths ={
	jade:['src/**/*.jade','!src/**/layout.jade'],
	copyImg:['src/img/**']
}

gulp.task('jade',function(){
	return gulp.src(paths.jade)
	.pipe(jade({pretty:true}))
	.pipe(gulp.dest('build'))
});

gulp.task('copy:img',function(){
	return gulp.src(paths.copyImg)
			.pipe(rev()).pipe(gulp.dest('build/img'))
			.pipe(rev.manifest()).pipe(gulp.dest('rev/img'))
})


gulp.task('rev',function(){
	return gulp.src(['rev/**/*.json','build/index.html','build/info/info.html'],{base:'build'})
	.pipe(revCollector({
		replaceReved: true
	}))
	.pipe( gulp.dest('build'));
})



gulp.task('browserify', function() {
	 browserify('src/js/app.js').bundle()
	.pipe(source('bundle.js'))
	.pipe(buffer())
	.pipe(uglify())
	.pipe(gulp.dest('build/js'));
});




gulp.task('watch',function(){
	gulp.watch(paths.jade,[jade])
})


